package com.xm;

import java.util.HashSet;

/**
 * @Author：xm
 * @Project：runoob
 * @Date：2024/7/14 19:37
 */

public class HashSet03 {
    public static void main(String[] args) {
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("a");
        hashSet.add("b");
        hashSet.add("c");
        System.out.println("hashSet = " + hashSet);

        // 重复元素不会被添加
        hashSet.add("b");
        System.out.println("hashSet = " + hashSet);

        System.out.println(hashSet.contains("c"));
        System.out.println(hashSet.contains("d"));

        System.out.println("hashSet.remove(\"c\") = " + hashSet.remove("c"));
        System.out.println(hashSet);

        System.out.println("hashSet.remove(\"d\") = " + hashSet.remove("d"));
        System.out.println(hashSet);

        // 删除集合中的所有元素
        // hashSet.clear();

        System.out.println(hashSet.size());

        for (String s : hashSet) {
            System.out.println("s = " + s);
        }
    }
}
